﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;

namespace DAO
{
    public class LapPhieuGiaoHangDao
    {
        public int LayMa()
        {
            DoixeDataContext DX = new DoixeDataContext();

            int Lable;
            Lable = 0;
            int MA = 0;
            while (Lable == 0)
            {
                IEnumerable<HOADONGIAOHANG> hdDto;
                hdDto = from hd in DX.HOADONGIAOHANGs where hd.MaHoaDon == MA select hd;
                if (hdDto.Count() != 0)
                {
                    MA++;
                }
                else
                {
                    Lable = 1;
                }
            }
            return MA;
        }
        public void LapPhieuGiaoHang(HOADONGIAOHANG HD)
        {
            DoixeDataContext DX = new DoixeDataContext();
            DX.HOADONGIAOHANGs.InsertOnSubmit(HD);
            DX.SubmitChanges();
        }
        public IEnumerable<HOADONGIAOHANG> LayHoaDon()
        {
            DoixeDataContext DX = new DoixeDataContext();
            return DX.HOADONGIAOHANGs;
        }
    }
}
